• Look at the following code:

  • int i
    {
      int j ;
      {
        int k ;
      }
    }

    Is i global or local?

    Can I access i from within the block where k is declared?

    What happens to the value of k when the its block is exited?

    If I declared a variable called i in the same block where k is declared, what happens?













    Answers
    1. i is global, as it is declared outside any block

    2. Yes, because you can always access variables from the enclosing block

    3. It is discarded

    4. The compiler is quite happy, but if you refer to i in this block you will get hold of the contents in that block. You won't be able to refer to the global i at all